NB IoT
This category contains functions specific to NB-IoT devices.
api.nbSend(addr, port, msg, timeout, type, nownewdatatimeout, rxport)
- Overview
- Arguments
- Example
Sends buffer msg to NB on specified IP, port and protocol type. Maximum length of Rx and Tx messages is 512 Bytes. Maximum execution time is limited by timeout milliseconds.
- addr (string) - IP address
- port (integer) - Port
- msg (string)(integer) - String to be sent to NB
- if number is provided instead of string, scratchpad (api.nbReceiveBuffer) buffer is sent in given length
- timeout (integer) - The maximum execution time in milliseconds
- type (string) - Protocol type, either UDP or TCP.
- nownewdatatimeout (integer, optional) - The maximum delay between data chunks on reception
- rxport (integer, optional) - Port to use for reception, if not specified, Port value is used
-- sends "test message" string to IP 185.8.239.192 on port 5566 with 6s timeout
status,answer = api.nbSend("185.8.239.192", 5566, "test message", 6000, "UDP")
api.nbReceiveBuffer(...)
- Overview
- Arguments
- Example
Function to activate, configure and use NB-IoT scratchpad buffer.
There are two options:
- api.nbReceiveBuffer(option, size):
- option (string) - arguments to manipulate with the buffer:
- "activate" - activate the buffer
- "deactivate" - deactivate the buffer
- "dump" - dump content of the buffer
- "set-size" - set size of the buffer
- "get-size" - get size of the buffer
- size (integer) - in combination with arguments
- "dump" - define size to dump (optional)
- "set-size" - define size of the buffer
- api.nbReceiveBuffer(start, len, toWrite):
- start (string) - index/location where the first byte will be written
- len (string) - length of data to write into the buffer
- toWrite (string) - data to write into the buffer
-- activate the buffer
api.nbReceiveBuffer("activate")
-- set size
api.nbReceiveBuffer("set-size", 128)
-- insert first byte
api.nbReceiveBuffer(0,1,pack.pack("b",0xF3))
-- send byte (starting from buffer index 1)
api.nbSend("185.8.239.192", 5566, 1, 6000, "UDP")
api.nbAT(command, arg2, wakeUp)
- Overview
- Commands
- Arguments
- Return
- Example #1
- Example #2
- Example #3
- Example #4
- Example #5
Sends an AT command to NB module with specified timeout. Or use one of the defined commands.
- "AT_DEBUG_OFF" - turn OFF printing of AT commands
- "AT_DEBUG_ON" - turn ON printing of AT commands
- "REINITIALIZE" - re-initialize the NB-IoT module
- "ICCID?" - returns ICCID value of current SIM card
- "IMSI?" - returns IMSI value of current SIM card
- "IMEI?" - returns IMEI value of the modem
- "DOWNLINK_MAX_PERIOD" - If there is no downlink for given value, set timeout to 30 seconds and re-initialize the module.
- "REINIT_HARD_LIMIT_RETRY" - If NB-IoT module is initialized 5 times in a row -> sleep 4 hours and then reset
- "FORCED_REINIT_DONE?" - monitors if "DOWNLINK_MAX_PERIOD" happened (1=true)
- "PSM" - returns power saving mode network status
- PSM state
- Edrx state
- Edrx Requested Value (Period)
- Edrx Requested Value (PTW)
- Keep Socket Open
- Force Rai Single UL
- Force Rel 13
- Compensate Timeout For Inact Timer
- "ON_TAU_EVENT" - enable/disable on tau event
- "SLEEP_MONITOR" - enable/disable sleep monitor, returns:
- Sleep Monitor status (enabled/disabled)
- Last Module Suspended Timestamp
- Module Sleep Failure Count
- "AT_DEBUG_ON_TX" - turn ON printing of AT commands on transmission
- "SET_CEREG_TRESHOLD" - set AT+CEREG switch threshold
- "TAU_BLANKING" - set Tau blanking interval
- "NET_STATUS?" - returns network status
- Last Tac
- Last Cell Id
- Last Periodic Tau
- Last Active Time
- Last Provided Edrx Value
- Last Provided Edrx Ptw Value
- Edrx Negotiated
- Compensate Timeout For Inact Timer Value
- "RADIO_OFF_SLEEP" - turn OFF radio sleep (PSM)
- "UPDATE" - switch to SIM module update mode
Default
- command (string) - AT command
- arg2 (integer) - The maximum execution time in milliseconds
- wakeUp (integer, optional) - Sending 1 will make sure that module is not asleep
Other
- "DOWNLINK_MAX_PERIOD" arg2 (integer) - time in milliseconds
- "REINIT_HARD_LIMIT_RETRY" arg2 (integer) - value defining how many times it will re-initialize module before reset
- answer (string) - Nil or non-zero length string with an answer to a AT command
- status (integer) - Zero for success, negative for failure
-- Get IMSI number of SIM card with timeout of 4 seconds
res = api.nbAT("AT+CIMI", 4000)
print(res)
-- IMEI --
x=api.nbAT("AT+CGSN")
start = string.find(x, "\n")
finish = string.find(x, "\r", start+1)
imei = string.sub(x,(start+1),(finish-1))
print("IMEI: " .. imei)
-- Get signal strength
res,b = api.nbAT("AT+CSQ")
print(res)
-- AT_DEBUG_OFF - turn off
-- AT_DEBUG_ON - turn on
-- REINITIALIZE - re-initialize the NB-IoT module
-- ICCID? - returns ICCID value of current SIM card
-- IMSI? - returns IMSI value of current SIM card
-- IMEI? - returns IMEI value of the modem
api.nbAT("AT_DEBUG_ON")
-- If there is no downlink for given value, set timeout to 30 seconds and re-initialize the module.
- api.nbAT("DOWNLINK_MAX_PERIOD", 3*24*3600*1000)
--if NB-IoT module is initialized 5 times in a row -> sleep 4 hours and then reset
- api.nbAT("REINIT_HARD_LIMIT_RETRY", 5)
-- "1" if DOWNLINK_MAX_PERIOD situation happened since reset.
- api.nbAT("FORCED_REINIT_DONE?")
api.nbReceiveBuffer(str)
- Overview
- Arguments
- Return
Enables internal buffer to receive NB data. Increases memory efficiency.
- str has 3 options:
- "activate" - activates the internal buffer
- "deactivate" - deactivates the internal buffer
- "dump" - dumps the internal buffer
- When "dump" option is used, functions returns the content of the buffer.